from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank, Size
from typing import List, Literal, Optional, Union
from module_admin.annotation.pydantic_annotation import as_query


class WlktsModel(BaseModel):
    """
    往来款提示对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='主键')
    title: Optional[str] = Field(default=None, description='名称')
    type: Optional[str] = Field(default=None, description='类型')
    amount: Optional[float] = Field(default=None, description='金额')
    party_b: Optional[str] = Field(default=None, description='对方')
    project_name: Optional[str] = Field(default=None, description='项目名称')
    project_cycle: Optional[str] = Field(default=None, description='项目周期')
    duty_dept: Optional[int] = Field(default=None, description='责任科室')
    duty_dept_name: Optional[str] = Field(default=None, description='责任科室名称')
    operator: Optional[str] = Field(default=None, description='经办人')
    phone: Optional[str] = Field(default=None, description='联系电话')
    end_time: Optional[datetime] = Field(default=None, description='到期时间')
    complete_time: Optional[datetime] = Field(default=None, description='完成时间')
    remark: Optional[str] = Field(default=None, description='备注')
    create_by: Optional[str] = Field(default=None, description='创建者')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_by: Optional[str] = Field(default=None, description='更新者')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')
    del_flag: Optional[str] = Field(default=None, description='删除标志（0代表存在 2代表删除）')

    @NotBlank(field_name='title', message='名称不能为空')
    def get_title(self):
        return self.title

    @NotBlank(field_name='type', message='类型不能为空')
    def get_type(self):
        return self.type

    @NotBlank(field_name='amount', message='金额不能为空')
    def get_amount(self):
        return self.amount

    @NotBlank(field_name='duty_dept', message='责任科室不能为空')
    def get_duty_dept(self):
        return self.duty_dept

    def validate_fields(self):
        self.get_title()
        self.get_type()
        self.get_amount()
        self.get_duty_dept()


class WlktsQueryModel(WlktsModel):
    """
    往来款提示不分页查询模型
    """
    begin_time: Optional[str] = Field(default=None, description='开始时间')
    end_time: Optional[str] = Field(default=None, description='结束时间')

@as_query
class WlktsPageQueryModel(WlktsQueryModel):
    """
    往来款提示分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class AddWlktsModel(WlktsModel):
    """
    新增往来款提示记录模型
    """
    pass


